package yunwo.cn.yzstation.model;

import android.util.Log;

import com.google.gson.Gson;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import yunwo.cn.yzstation.api.HttpManager;
import yunwo.cn.yzstation.api.okapi.GLCallBack;
import yunwo.cn.yzstation.bean.GoodsinfoitemBean;
import yunwo.cn.yzstation.config.MyConstants;
import yunwo.cn.yzstation.presenter.GoodsInfoFramgnetPresenter;
import yunwo.cn.yzstation.presenter.IGoodsinfoModel;
import yunwo.cn.yzstation.utils.StringUtil;
import yunwo.cn.yzstation.view.activity.CarsDetailsActivity;

/**
 * Created by lao on 2017/10/13.
 */
public class GoodsInfoModel {
    CarsDetailsActivity carsDetailsActivity;
    IGoodsinfoModel goodsinfoModel;

    public GoodsInfoModel(CarsDetailsActivity carsDetailsActivity, IGoodsinfoModel goodsinfoModel) {
        this.carsDetailsActivity = carsDetailsActivity;
        this.goodsinfoModel = goodsinfoModel;
    }

    public void getData(String departId, final String type, int page, int size) {
        Map<String, Object> map = new HashMap<>();
        map.put("departId", departId);
        HttpManager.hpptPostPageStringmer(MyConstants.trackinglist,page,size,map).execute(new GLCallBack() {

            private GoodsinfoitemBean.DataBean mDataBean;

            @Override
            public void onResponseT(String result, int code, String msg, int id) {
                if (code == 200) {
                    if (!StringUtil.isEmpty(result)) {
                        mDataBean = new Gson().fromJson(result, GoodsinfoitemBean.DataBean.class);
                        goodsinfoModel.getDataSueecss(type, mDataBean);
                    }
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                goodsinfoModel.getDatafailure();
            }
        });
    }
}
